package interfaceCustomer;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

public class CustomerSendComplaintPanel extends JPanel implements ActionListener  {
	
	private JButton btnSend, btnBackToMenu;
	private JLabel lblCusId, lblCusName, lblCarId, lblLength;
	final   JLabel lblDesc;                                   //final????????????????????
	private JTextField txtCarId, txtCusName, txtCusId;
	private JTextArea txtDesc;
	private JScrollPane sp;
	private CustomerFrame backtomenu;  //reference to menu

	public CustomerSendComplaintPanel(CustomerFrame _cf) {
		
		backtomenu = _cf;
		this.setLayout(null);

		btnSend = new JButton("Send Complaint");
		btnSend.setBounds(473, 214, 132, 25);
		this.add(btnSend);
		btnSend.addActionListener(this);	
		
		btnBackToMenu = new JButton("Back To Menu");
		btnBackToMenu.setBounds(88, 214, 126, 25);
		this.add(btnBackToMenu);
		btnBackToMenu.addActionListener(this);
		
		lblCusId = new JLabel("Customer ID:");
		lblCusId.setBounds(99, 10, 75, 25);
		this.add(lblCusId);
		
		lblCusName = new JLabel("Customer Name:");
		lblCusName.setBounds(269, 10, 97, 25);
		this.add(lblCusName);
				
		lblDesc = new JLabel("Description:");
		lblDesc.setBounds(12, 93, 75, 20);
		this.add(lblDesc);
		
		lblLength = new JLabel("0/3,500");
		lblLength.setBounds(22, 117, 50, 25);
		this.add(lblLength);
		
		txtCusId = new JTextField();
		txtCusId.setBounds(179, 12, 80, 20);
		this.add(txtCusId);
		txtCusId.setEditable(false);
		
		txtCusName = new JTextField();
		txtCusName.setBounds(371, 12, 80, 20);
		this.add(txtCusName);
		txtCusName.setEditable(false);
		
		txtCarId = new JTextField();
		txtCarId.setBounds(514, 12, 80, 20);
		this.add(txtCarId);
		txtCarId.setEditable(false);
	
		txtDesc = new JTextArea();        //needs to limit the characters number in this textArea!!!
		txtDesc.setBounds(90, 45, 517, 150);
		txtDesc.setLineWrap(true);
		this.add(txtDesc);
		
		sp= new JScrollPane(txtDesc);
		sp.setBounds(90, 45, 517, 150);
		this.add(sp);
		
		lblCarId = new JLabel("Car ID:");
		lblCarId.setBounds(468, 15, 50, 14);
		this.add(lblCarId);
		
		txtDesc.getDocument().addDocumentListener(new DocumentListener() {
		    public void changedUpdate(DocumentEvent e) {      //shuld be here?or outside constructor
		        update();
		    }

		    public void removeUpdate(DocumentEvent e) {
		        update();
		    }

		    public void insertUpdate(DocumentEvent e) {
		        update();
		    }

		    public void update() {
		        lblLength.setText(txtDesc.getText().length()+"/ 3,500");
		    }
		});
		
		this.setVisible(true);
	}
	

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == btnBackToMenu) {
			backtomenu.ChangePanel(0);
		}
		if(e.getSource() == btnSend) {
			JOptionPane.showMessageDialog(this,"Your Order Was Confraimed","OK",JOptionPane.INFORMATION_MESSAGE);
		}
	}
}